
/*
 * Copyright (c) 2010 Sergey N Frolov
 * 
 * See LICENSE file
 */

#ifndef _NGX_JAVASCRIPT_MODULE_SQLITE_H_INCLUDED_
#define _NGX_JAVASCRIPT_MODULE_SQLITE_H_INCLUDED_

#include "ngx_javascript.h"

#include <sqlite3.h>

JSBool ngx_javascript_init_sqlite(JSContext *jcx, JSObject *global);

void ngx_javascript_sqlite_finalize(JSContext *jcx, JSObject *obj);
JSBool ngx_javascript_sqlite(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool ngx_javascript_sqlite_prepare(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool ngx_javascript_sqlite_execute(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool ngx_javascript_sqlite_quote(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool ngx_javascript_sqlite_escape(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool ngx_javascript_sqlite_close(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);

JSBool ngx_javascript_sqlite_query(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval, int todo);

void ngx_javascript_sqlite_result_finalize(JSContext *jcx, JSObject *obj);
JSBool ngx_javascript_sqlite_result_bind(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool ngx_javascript_sqlite_result_execute(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool ngx_javascript_sqlite_result_length(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool ngx_javascript_sqlite_result_fetchArray(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool ngx_javascript_sqlite_result_fetchObject(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool ngx_javascript_sqlite_result_finish(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);

jsval ngx_javascript_sqlite_get_value(JSContext *jcx, sqlite3_stmt *st, int i);

JSBool ngx_javascript_sqlite_result_fetch_value(JSContext *jcx, JSObject *obj, uintN argc, jsval *argv, jsval *rval, int todo);
JSBool ngx_javascript_sqlite_result_bind_value(JSContext *jcx, sqlite3_stmt *st, jsuint i, jsval result);

JSBool ngx_javascript_sqlite_error(JSContext *jcx, int code, const char *message);

#define NGX_JAVASCRIPT_SQLITE_PREPARE 0
#define NGX_JAVASCRIPT_SQLITE_EXECUTE 1
#define NGX_JAVASCRIPT_SQLITE_FETCH_ARRAY 0
#define NGX_JAVASCRIPT_SQLITE_FETCH_OBJECT 1

#endif /* _NGX_JAVASCRIPT_MODULE_SQLITE_H_INCLUDED_ */
